﻿using System.Runtime.CompilerServices;

namespace Index.TreeIndex
{
    public class UintDigits
    {
        private const int size = 8;
        private const int maxIndex = 7;
        private const int digitSize = 4;

        public readonly int[] Digits;

        public int CurrentDigit
        {
            get { return this.Digits[this.Index]; }
        }

        public int Index { get; private set; }

        public bool IsLastDigit
        {
            get { return this.Index == maxIndex; }
        }

        public UintDigits(uint value)
        {
            this.Digits = new int[size];

            uint mask = 0x0000000f;
            int shift = 0;

            for (int k = 0; k < size; k++ )
            {
                this.Digits[k] = (int) (value & mask) >> shift;
                mask = mask << digitSize;
                shift = shift + digitSize;
            }

            this.Index = 0;
        }

        public bool NextDigit()
        {
            if(this.Index < maxIndex)
            {
                this.Index++;
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}